package o2o.web.actions.shop;

import com.jinyou.utils.common.*;
import o2o.cache.agent.CityAgentMemory;
import o2o.cache.agent.ShopAgentRelationMemory;
import o2o.cache.order.OrderInfoMemory;
import o2o.cache.order.user.UserOrderMemoryMan;
import o2o.cache.shop.*;
import o2o.config.dao.UserDaoSql;
import o2o.dao.PO.PojoTables;
import o2o.dao.PO.agent.CityAgent;
import o2o.dao.PO.order.ORDER_TYPE;
import o2o.dao.PO.order.OrderInfo;
import o2o.dao.PO.shop.*;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.VO.agent.CityAgentVO;
import o2o.dao.VO.shop.ShopInfoAndGameVO;
import o2o.dao.VO.shop.ShopInfoVO;
import o2o.service.shop.ShopBannerService;
import o2o.service.shop.ShopTypeService;
import o2o.company.model.ShopInfo;
import o2o.system.data.SHOP_MANAGE_TYPE_FREE_OR_AGENT;
import o2o.system.data.SYS_SETTINGS;
import o2o.web.actions.agent.CityAgentMan;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;


@Controller
public class ShopListMan {

    private static ConcurrentHashMap<Long, ShopGoodsNumber> shopGoodsNumberCache = new ConcurrentHashMap<>();


    //--------------------------------------------------------------------------------------------------------------------------
    //获取店铺列表
    public static JYPageUtils.PageList getShopList(UserInfo user,//用来判断是否收藏过
                                                   boolean checkTypeId,//检测不同类型店铺
                                                   Integer typeId,//不同类型店铺（检测店铺类型时，此参数才有效）
                                                   String city,
                                                   Long regionId,
                                                   Long agentId,//精确商圈代理Id
                                                   Double lng, Double lat,
                                                   String content,//检索内容
                                                   Boolean checkRecommend,//是否检测是否推荐
                                                   Boolean isRecommend,//是否推荐（只有检测推荐时，此参数才有效）
                                                   boolean hasGameInfo,//是否包含活动信息
                                                   Integer orderType,//排序方式   1综合排序  2距离排序 3销量排序 4评分最高 5起送加最低
                                                   String filterType,//筛选条件
                                                   Integer shopCategory,//  商家类型
                                                   Integer needGoods, // 店铺需要返回商品列表
                                                   Integer needGoodsCount, // 店铺需要返回商品列表
                                                   FilterConditionUtils filterConditionUtils, // 条件类
                                                   Integer page, Integer size) {
        return getShopList(user, checkTypeId, typeId, city, regionId, agentId, lng, lat, content, checkRecommend, isRecommend, false, false, hasGameInfo, orderType, filterType, shopCategory, needGoods, needGoodsCount, filterConditionUtils, page, size);
    }


    public static JYPageUtils.PageList getShopList(UserInfo user,//用来判断是否收藏过
                                                   boolean checkTypeId,//检测不同类型店铺
                                                   Integer typeId,//不同类型店铺（检测店铺类型时，此参数才有效）
                                                   String city,
                                                   Long regionId,
                                                   Long agentId,//精确商圈代理Id
                                                   Double lng, Double lat,
                                                   String content,//检索内容
                                                   Boolean checkRecommend,//是否检测是否推荐
                                                   Boolean isRecommend,//是否推荐（只有检测推荐时，此参数才有效）
                                                   Boolean checkIsPreference,//是否检测是否优选
                                                   Boolean isPreference, //是否为优选（只有检测推荐时，此参数才有效）
                                                   boolean hasGameInfo,//是否包含活动信息
                                                   Integer orderType,//排序方式   1综合排序  2距离排序 3销量排序 4评分最高 5起送加最低
                                                   String filterType,//筛选条件
                                                   Integer shopCategory,//是不是团购商家
                                                   Integer needGoods, // 店铺需要返回商品列表
                                                   Integer needGoodsCount, // 店铺需要返回商品列表
                                                   FilterConditionUtils filterConditionUtils, // 条件类
                                                   Integer page, Integer size) {

        if (null == typeId) {
            checkTypeId = false;
        }

        //是否需要获取店铺当前实时位置
        boolean needShopNowPosition = SYS_SETTINGS.SHOP_NOW_POSITION_NEED != null && SYS_SETTINGS.SHOP_NOW_POSITION_NEED == 1;

        HashSet<Integer> filterSet = filterToSet(filterType);
        Set<Long> userBuyShopIdSet = null;
        if (filterSet != null && filterSet.contains(SHOP_FILTER_TYPE.FREQUENT_STROLL) && user != null) {
            List<OrderInfo> infoList = UserOrderMemoryMan.listOfUser(user.getUsername(), ORDER_TYPE.SHOP_GOODS);
            if (ValidateUtil.isAbsList(infoList)) {
                userBuyShopIdSet = infoList.stream().map(bean -> bean.getShopId()).collect(Collectors.toSet());
            }
        }

        // 获取全国店铺
        List<ShopInfo> specialList = new ArrayList<>();
        if (null != SYS_SETTINGS.SHOW_SPECIAL_SHOP && 0 == 1 - SYS_SETTINGS.SHOW_SPECIAL_SHOP) {
            HashSet<Long> set = SpecialShopListMemory.getInstance().listOfType(SPECIAL_SHOP_LIST_TYPE.ALL_COUNTRY);
            if (null != set && set.size() > 0) {
                for (Long shopId : set) {
                    if (ValidateUtil.isNotID(shopId)) {
                        continue;
                    }
                    ShopInfo shopInfo = ShopMemory.getInstance().getShopById(shopId);
                    if (null == shopInfo) {
                        continue;
                    }
                    specialList.add(shopInfo);
                }
            }
        }

        List<ShopInfo> list = null;
        if (ValidateUtil.isID(agentId)) {
            list = ShopMan.listOfAgentId(agentId, typeId, content, checkRecommend, isRecommend, checkIsPreference, isPreference);
            // 排序
            if (ValidateUtil.isAbsList(list)) {
                // 添加全国店铺
                if (ValidateUtil.isAbsList(specialList)) {
                    list.addAll(specialList);
                    // 去重
                    list = list.stream().distinct().collect(Collectors.toList());
                }

                //modify by liumingyao 2017-11-29
                if (ValidateUtil.isNotAbsInteger(orderType)) {
                    orderType = SHOP_LIST_ORDER_TYPE.AGGREGATE;
                }
            }
        } else {
            if (ValidateUtil.isLatLng(lat, lng)) {
                //精确商圈方式
                if (null != SYS_SETTINGS.SHOP_MANAGE_TYPE && 0 == SHOP_MANAGE_TYPE_FREE_OR_AGENT.AGENT - SYS_SETTINGS.SHOP_MANAGE_TYPE) {
                    //单商圈还是多商圈同时返回
                    if (null != SYS_SETTINGS.LOCAL_CITY_AGENT_TYPE && 0 == SYS_SETTINGS.LOCAL_CITY_AGENT_TYPE) {     // 定位时城市按下商圈列表还是单独商圈  1单独商圈，0商圈列表
                        //商圈列表
                        List<CityAgentVO> agentList = CityAgentMan.getCityAgentList(city, lat, lng);
                        if (ValidateUtil.isAbsList(agentList)) {
                            list = new ArrayList<>();
                            for (int i = 0; i < agentList.size(); i++) {
                                CityAgentVO agentVO = agentList.get(i);
                                if (agentVO != null) {
                                    List<Long> tmpList = ShopAgentRelationMemory.getInstance().listOfAgentId(agentVO.getId());

                                    if (!ValidateUtil.isAbsList(tmpList)) {
                                        continue;
                                    }
                                    List<ShopInfo> tList = convertShopList(agentVO, tmpList, lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, needShopNowPosition, shopCategory, userBuyShopIdSet, filterSet);
                                    if (ValidateUtil.isAbsList(tList)) {
                                        list.addAll(tList);
                                    }
                                }
                            }
                        }

                    } else {
                        //单独商圈
                        CityAgentVO cityAgentVO = CityAgentMan.getCityAgent(city, lat, lng);
                        if (null == cityAgentVO) {
                            if (null != SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT && 0 == 1 - SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT) {
                                list = getDefaultShopList(lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, needShopNowPosition, shopCategory, filterSet);
                            } else {
                                return null;
                            }
                        } else {
                            List<Long> shopIds = ShopAgentRelationMemory.getInstance().listOfAgentId(cityAgentVO.getId());

                            if (ValidateUtil.isAbsList(shopIds)) {
                                list = convertShopList(cityAgentVO, shopIds, lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, needShopNowPosition, shopCategory, userBuyShopIdSet, filterSet);
                            }
                        }

                    }

                } else {
                    Long areaPoint = Geohash.getArea(lat, lng);
                    int range = 15;//大概是10公里
                    if (ValidateUtil.isAbsInteger(SYS_SETTINGS.SHOP_RANGE)) {
                        range = SYS_SETTINGS.SHOP_RANGE;
                    }
                    Set<Long> areaPoints = Geohash.getAroundArea(areaPoint, range);
                    if (ValidateUtil.isID(regionId)) {
                        List<ShopRegionRelation> relationList = ShopRegionRelationMemory.getInstance().listOfRegionId(regionId);
                        if (ValidateUtil.isAbsList(relationList)) {
                            for (int i = 0; i < relationList.size(); i++) {
                                if (null == relationList.get(i)) {
                                    continue;
                                }
                                ShopInfo shopInfo = ShopMemory.getInstance().getShopById(relationList.get(i).getShopId());
                                if (!isUsefulShop(shopInfo, lat, lng, checkRecommend, false, checkTypeId, typeId, content, shopCategory, userBuyShopIdSet, filterSet)) {
                                    continue;
                                }

                                if (!areaPoints.contains(shopInfo.getAreaPoint())) {
                                    continue;
                                }

                                //获取店铺当前位置
                                if (needShopNowPosition) {
                                    shopInfo = setShopNowPosition(shopInfo);
                                }
                                shopInfo.setDistinct(Geohash.distance(lat, lng, shopInfo.getLat(), shopInfo.getLng()));
                                list.add(shopInfo);
                            }
                        }
                    } else {
                        List<ShopInfo> tmp = ShopMemory.getInstance().list(checkTypeId, typeId,
                                city, "", "",
                                content,
                                checkRecommend, isRecommend, checkIsPreference, isPreference);//该城市店铺列表
                        if (ValidateUtil.isAbsList(tmp)) {
                            list = new ArrayList<>();
                            for (int i = 0; i < tmp.size(); i++) {
                                if (null == tmp.get(i)) {
                                    continue;
                                }
                                if (ValidateUtil.isNotLatLng(lat, lng)) {
                                    continue;
                                }
                                if (ValidateUtil.isNotAbsLong(tmp.get(i).getAreaPoint())) {
                                    continue;
                                }
                                if (!areaPoints.contains(tmp.get(i).getAreaPoint())) {
                                    continue;
                                }

                                //获取店铺当前位置
                                if (needShopNowPosition) {
                                    ShopInfo shopInfo = setShopNowPosition(tmp.get(i));
                                    tmp.get(i).setLat(shopInfo.getLat());
                                    tmp.get(i).setLng(shopInfo.getLng());
                                }
                                tmp.get(i).setDistinct(Geohash.distance(lat, lng, tmp.get(i).getLat(), tmp.get(i).getLng()));
                                list.add(tmp.get(i));
                            }
                        }
                    }

                }

                if (ValidateUtil.isAbsList(list)) {

                    // 添加全国店铺
                    if (ValidateUtil.isAbsList(specialList)) {
                        if (!ValidateUtil.isAbsList(list)) {
                            list = new ArrayList<>();
                        }
                        list.addAll(specialList);
                        // 去重
                        list = list.stream().distinct().collect(Collectors.toList());

                    }

                    if (ValidateUtil.isNotAbsInteger(orderType)) {
                        orderType = SHOP_LIST_ORDER_TYPE.AGGREGATE;
                    }
                } else {
                    if (null != SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT && 0 == 1 - SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT) {
                        list = getDefaultShopList(lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, needShopNowPosition, shopCategory, filterSet);

                        // 添加全国店铺
                        if (ValidateUtil.isAbsList(specialList)) {
                            if (!ValidateUtil.isAbsList(list)) {
                                list = new ArrayList<>();
                            }
                            list.addAll(specialList);
                            // 去重
                            list = list.stream().distinct().collect(Collectors.toList());
                        }
                    } else {
                        return null;
                    }
                }
            } else {
                list = ShopMemory.getInstance().list(checkTypeId, typeId,
                        city, "", "",
                        content,
                        checkRecommend, isRecommend, checkIsPreference, isPreference);//该城市店铺列表  管理后台可能用到
                if (ValidateUtil.isAbsList(list)) {
                    Set<Long> finalUserBuyShopIdSet = userBuyShopIdSet;
                    list = list.stream().filter(item -> screenShopFilter(filterSet, finalUserBuyShopIdSet, item)).collect(Collectors.toList());
                }
                // 添加全国店铺
                if (ValidateUtil.isAbsList(specialList)) {
                    if (!ValidateUtil.isAbsList(list)) {
                        list = new ArrayList<>();
                    }
                    list.addAll(specialList);
                    // 去重
                    list = list.stream().distinct().collect(Collectors.toList());
                }
            }
        }

        if (!ValidateUtil.isAbsList(list)) {
            if (null != SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT && 0 == 1 - SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT) {
                list = getDefaultShopList(lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, needShopNowPosition, shopCategory, filterSet);
            } else {
                return null;
            }
        }
        if (ValidateUtil.isNotAbsInteger(orderType)) {
            orderType = SHOP_LIST_ORDER_TYPE.AGGREGATE;
        }

        // 删除积分商城的店铺
        final Integer sortType = orderType;
        Integer maxOrderCount = 0;
        if (ValidateUtil.isAbsList(list)) {
            list = list.stream().filter(bean -> vaildShop(bean, shopCategory, checkRecommend, filterConditionUtils == null ? null : filterConditionUtils.getReCategoryId())).map(a -> getShopDis(a, sortType, lat, lng)).collect(Collectors.toList());
            if (sortType == SHOP_LIST_ORDER_TYPE.AGGREGATE) {
                for (ShopInfo info : list) {
                    if (null == info) {
                        continue;
                    }
                    if (maxOrderCount <= info.getOrderCounts()) {
                        maxOrderCount = info.getOrderCounts();
                    }
                }
            }
        }
        //把推荐的店铺放在上面
        if (null == page || page < 1) {
            page = 1;
        }
        if (null == size || size < 1) {
            size = 10;
        }

        //
        if (ValidateUtil.isAbsList(list) || (filterConditionUtils != null && filterConditionUtils.isCheckCloudSquareShop())) {
            List<ShopInfoAndGameVO> voList = new ArrayList<>();
            if (ValidateUtil.isAbsList(list)) {
                for (ShopInfo shopInfo : list) {
                    if (null == list) {
                        continue;
                    }
                    ShopInfoAndGameVO shopInfoVO = getShop(user, shopInfo, hasGameInfo, needGoods, needGoodsCount, null);
                    if (null == shopInfoVO) {
                        continue;
                    }
                    if (shopInfoVO.getScore() == null) {
                        shopInfoVO.setScore(0.0);
                    }
                    if (shopInfoVO.getStartFree() == null) {
                        shopInfoVO.setStartFree(0.0);
                    }
                    if (shopInfoVO.getOrderNo() == null) {
                        shopInfoVO.setOrderNo(0L);
                    }
                    // order2 越小比重越到，越排在前面
                    if (orderType == SHOP_LIST_ORDER_TYPE.AGGREGATE) {
                        // 销量 最大销量/当前销量
                        // 距离 当前距离*0.36/100
                        Double sis = 10000d;
                        if (maxOrderCount != 0) {
                            if (shopInfoVO.getOrderCounts() > 0) {
                                sis = JYMathDoubleUtils.div(maxOrderCount, shopInfoVO.getOrderCounts());
                            } else {
                                sis = Double.parseDouble(maxOrderCount + "");
                            }
                        }
                        if (shopInfoVO.getDistinct() > 0) {
                            double d2 = JYMathDoubleUtils.div(JYMathDoubleUtils.sub(shopInfo.getDistinct(), 0.36), 100);
                            if (d2 > 0) {
                                sis = JYMathDoubleUtils.add(sis, d2);
                            }
                        }
                        if (sis > 0) {
                            shopInfoVO.setOrderNo2(sis);
                        }
                    }

                    voList.add(shopInfoVO);
                }
            }

            if (ValidateUtil.isAbsList(voList)) {
                // 处理一下数据条数问题

                Comparator<ShopInfoAndGameVO> work = Comparator.comparingInt(ShopInfoAndGameVO::getIsWork).reversed();
                Comparator<ShopInfoAndGameVO> recommend = Comparator.comparingInt(ShopInfoAndGameVO::getIsRecommend).reversed();
                if (null != orderType) {
                    switch (orderType) {
                        case SHOP_LIST_ORDER_TYPE.AGGREGATE: {//综合排序
                            // 先是上班的  在按照序号排序  在按照距离排序
                            Collections.sort(
                                    voList,
                                    work.thenComparing(Comparator.comparingLong(ShopInfoAndGameVO::getOrderNo))
                                            .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getOrderNo2))
                            );
                        }
                        break;
                        case SHOP_LIST_ORDER_TYPE.SPEED: {//速度最快
                            // 先是上班的  在按照序号排序  在按照距离排序
                            Collections.sort(voList, work.thenComparing(Comparator.comparingLong(ShopInfoAndGameVO::getOrderNo))
                                    .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getDistinct)));
                        }
                        break;
                        case SHOP_LIST_ORDER_TYPE.DISTANCE: {// 距离排序
                            // 先上下班  在 距离 在推荐
                            Collections.sort(voList, work
                                    .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getDistinct)).thenComparing(recommend));
                        }
                        break;
                        case SHOP_LIST_ORDER_TYPE.SELL_COUNT: {//销量排序
                            Comparator<Object> countComparator = Comparator.comparingInt(e -> addSellCount((ShopInfoAndGameVO) e)).reversed();
                            Collections.sort(voList, work
                                    .thenComparing(countComparator)
                                    .thenComparing(recommend));
                        }
                        break;
                        case SHOP_LIST_ORDER_TYPE.SCORE: {// 评分最高
                            Collections.sort(voList, work
                                    .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getScore).reversed()).thenComparing(recommend));
                        }
                        break;
                        case SHOP_LIST_ORDER_TYPE.DELIVERY_PRICE: {// 起送加最低
                            Collections.sort(voList, work
                                    .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getStartFree)).thenComparing(recommend));
                        }
                        break;
                    }
                } else {
                    Collections.sort(voList, work
                            .thenComparing(Comparator.comparingLong(ShopInfoAndGameVO::getOrderNo)).thenComparing(recommend));
                }
                return JYPageUtils.getList(voList, page, size);
            }
        }
        return null;
    }




    public static JYPageUtils.PageList getGroupShopList(UserInfo user,//用来判断是否收藏过
                                                        boolean checkTypeId,//检测不同类型店铺
                                                        Integer typeId,//不同类型店铺（检测店铺类型时，此参数才有效）
                                                        String city,
                                                        Long agentId,//精确商圈代理Id
                                                        Double lng, Double lat,
                                                        String content,//检索内容
                                                        Boolean checkRecommend,//是否检测是否推荐
                                                        Boolean isRecommend,//是否推荐（只有检测推荐时，此参数才有效）
                                                        Boolean checkIsPreference,//是否检测是否优选
                                                        Boolean isPreference, //是否为优选（只有检测推荐时，此参数才有效）
                                                        Integer orderType,//排序方式   1综合排序  2距离排序 3销量排序 4评分最高 5起送加最低
                                                        String filterType,//筛选条件
                                                        Integer needGoods, // 店铺需要返回商品列表
                                                        Integer needGoodsCount, // 店铺需要返回商品列表
                                                        FilterConditionUtils filterConditionUtils,
                                                        Integer page, Integer size) {
        if (null == typeId) {
            checkTypeId = false;
        }
        //是否需要获取店铺当前实时位置
        HashSet<Integer> filterSet = filterToSet(filterType);
        List<ShopInfo> list = null;
        if (ValidateUtil.isID(agentId)) {
            list = ShopMan.listOfAgentId(agentId, typeId, null, content, checkRecommend, isRecommend, null, ShopCategoryMan.shopTypeGroup, checkIsPreference, isPreference);
        } else {
            list = ShopMemory.getInstance().list(checkTypeId, typeId,
                    city, "", "",
                    content,
                    checkRecommend, isRecommend, checkIsPreference, isPreference, SHOP_ROLE.NORMAL, null, ShopCategoryMan.shopTypeGroup, null, true, CLOUD_SHOP_TYPE.CLOUD_SHOP_TYPE_ORDINARY);
        }
        if (ValidateUtil.isNotAbsInteger(orderType)) {
            orderType = SHOP_LIST_ORDER_TYPE.AGGREGATE;
        }
        final boolean isCheckTypeId = checkTypeId;
        final Integer sortType = orderType;
        Integer maxOrderCount = 0;
        if (ValidateUtil.isAbsList(list)) {
            list = list.stream().filter(bean -> isUsefulShop(bean, lat, lng, checkRecommend, checkIsPreference, isCheckTypeId, typeId, content, ShopCategoryMan.shopTypeGroup, null, filterSet)).filter(bean -> vaildShop(bean, ShopCategoryMan.shopTypeGroup, checkRecommend, null)).map(a -> getShopDis(a, sortType, lat, lng)).collect(Collectors.toList());
            if (sortType == SHOP_LIST_ORDER_TYPE.AGGREGATE) {
                for (ShopInfo info : list) {
                    if (null == info) {
                        continue;
                    }
                    if (maxOrderCount <= info.getOrderCounts()) {
                        maxOrderCount = info.getOrderCounts();
                    }
                }
            }
        }
        //把推荐的店铺放在上面
        if (null == page || page < 1) {
            page = 1;
        }
        if (null == size || size < 1) {
            size = 10;
        }
        //
        if (ValidateUtil.isAbsList(list)) {
            List<ShopInfoAndGameVO> voList = new ArrayList<>();
            for (ShopInfo shopInfo : list) {
                if (null == shopInfo || shopInfo.getIsLock() == 0) {
                    // 锁定的不要~
                    continue;
                }
                ShopInfoAndGameVO shopInfoVO = getShop(user, shopInfo, false, needGoods, needGoodsCount, ShopCategoryMan.shopTypeGroup);
                if (null == shopInfoVO) {
                    continue;
                }

                shopInfoVO.setShopId(shopInfoVO.getId());
                if (shopInfoVO.getScore() == null) {
                    shopInfoVO.setScore(0.0);
                }
                if (shopInfoVO.getStartFree() == null) {
                    shopInfoVO.setStartFree(0.0);
                }
                if (shopInfoVO.getOrderNo() == null) {
                    shopInfoVO.setOrderNo(0L);
                }
                Long agent = ShopAgentRelationMemory.getInstance().getAgentByShopId(shopInfoVO.getId());
                if (ValidateUtil.isID(agent)) {
                    CityAgent cityAgent = CityAgentMemory.getInstance().getById(agent);
                    if (cityAgent != null) {
                        shopInfoVO.setCityAgentName(cityAgent.getName());
                    }
                }
                // order2 越小比重越到，越排在前面
                if (orderType == SHOP_LIST_ORDER_TYPE.AGGREGATE) {
                    // 销量 最大销量/当前销量
                    // 距离 当前距离*0.36/100
                    Double sis = 10000d;
                    if (maxOrderCount != 0) {
                        if (shopInfoVO.getOrderCounts() > 0) {
                            sis = JYMathDoubleUtils.div(maxOrderCount, shopInfoVO.getOrderCounts());
                        } else {
                            sis = Double.parseDouble(maxOrderCount + "");
                        }
                    }
                    if (shopInfoVO.getDistinct() > 0) {
                        double d2 = JYMathDoubleUtils.div(JYMathDoubleUtils.sub(shopInfo.getDistinct(), 0.36), 100);
                        if (d2 > 0) {
                            sis = JYMathDoubleUtils.add(sis, d2);
                        }
                    }
                    if (sis > 0) {
                        shopInfoVO.setOrderNo2(sis);
                    }
                }
                // 查看商家的关联的行业分类
                shopInfoVO.setShopType(ShopTypeService.getInstance().findShopTypeList(shopInfoVO.getId()));
                // 商家轮播图
                shopInfoVO.setShopBanners(ShopBannerService.getInstance().findShopBannerList(shopInfoVO.getId(), null));
                voList.add(shopInfoVO);
            }
            if (ValidateUtil.isAbsList(voList)) {
                sortShopAndGameList(voList, orderType);
                return JYPageUtils.getList(voList, page, size);
            }
        }
        return null;
    }

    public static void sortShopAndGameList(List<ShopInfoAndGameVO> voList, Integer sortType) {
        Comparator<ShopInfoAndGameVO> work = Comparator.comparingInt(ShopInfoAndGameVO::getIsWork).reversed();
        Comparator<ShopInfoAndGameVO> cloudShopCompare = Comparator.comparingInt(ShopInfoAndGameVO::getCloudShopType).reversed();
        Comparator<ShopInfoAndGameVO> recommend = Comparator.comparingInt(ShopInfoAndGameVO::getIsRecommend).reversed();
        if (null != sortType) {
            switch (sortType) {
                case SHOP_LIST_ORDER_TYPE.AGGREGATE: {//综合排序
                    // 先是上班的  在按照序号排序  在按照距离排序
                    Collections.sort(
                            voList,
                            work.thenComparing(cloudShopCompare)
                                    .thenComparing(Comparator.comparingLong(ShopInfoAndGameVO::getOrderNo))
                                    .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getOrderNo2))
                    );
                }
                break;
                case SHOP_LIST_ORDER_TYPE.SPEED: {//速度最快
                    // 先是上班的  在按照序号排序  在按照距离排序
                    Collections.sort(voList, work.thenComparing(Comparator.comparingLong(ShopInfoAndGameVO::getOrderNo))
                            .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getDistinct)));
                }
                break;
                case SHOP_LIST_ORDER_TYPE.DISTANCE: {// 距离排序
                    // 先上下班  在 距离 在推荐
                    Collections.sort(voList, work
                            .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getDistinct)).thenComparing(recommend));
                }
                break;
                case SHOP_LIST_ORDER_TYPE.SELL_COUNT: {//销量排序
                    Comparator<Object> countComparator = Comparator.comparingInt(e -> addSellCount((ShopInfoAndGameVO) e)).reversed();
                    Collections.sort(voList, work
                            .thenComparing(countComparator)
                            .thenComparing(recommend));
                }
                break;
                case SHOP_LIST_ORDER_TYPE.SCORE: {// 评分最高
                    Collections.sort(voList, work
                            .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getScore).reversed()).thenComparing(recommend));
                }
                break;
                case SHOP_LIST_ORDER_TYPE.DELIVERY_PRICE: {// 起送加最低
                    Collections.sort(voList, work
                            .thenComparing(Comparator.comparingDouble(ShopInfoAndGameVO::getStartFree)).thenComparing(recommend));
                }
                break;
            }
        } else {
            Collections.sort(voList, work
                    .thenComparing(Comparator.comparingLong(ShopInfoAndGameVO::getOrderNo)).thenComparing(recommend));
        }
    }

    public static Integer addSellCount(ShopInfoAndGameVO shopInfoAndGameVO) {
        Integer counts = 0;
        if (SYS_SETTINGS.SELL_COUNT_TYPE == 0) {
            counts = shopInfoAndGameVO.getMonthOrderCount();
        } else {
            counts = shopInfoAndGameVO.getOrderCounts();
        }
        if (SYS_SETTINGS.HAS_SHOW_SELL_COUNT == 1) {
            if (shopInfoAndGameVO.getShowOrderCounts() != null) {
                counts += shopInfoAndGameVO.getShowOrderCounts();
            }
        }
        return counts;
    }


    public static boolean vaildShop(ShopInfo bean, Integer shopCategory, boolean checkRecommend, Long reCommendCategoryId) {
        if (bean == null) {
            return false;
        }
        if (shopCategory == null) {
            shopCategory = ShopCategoryMan.shopTypeShopping; // 默认是外卖商家
        }
        if (bean.getShopCategory() != null && !ShopCategoryMan.validShopType(shopCategory, bean.getShopCategory())) {
            return false;
        }
        if (!(bean.getIsIntegralShop() == null || bean.getIsIntegralShop() == SHOP_IS_INTEGRAL.NON_INTEGRAL_SHOP || bean.getIsIntegralShop() == SHOP_IS_INTEGRAL.BOTH_SHOP)) {
            return false;
        }
        if (SYS_SETTINGS.DISTINGUISH_SHOP_RECOMMEND == 1 && shopCategory != null && (bean.getCloudShopType() == null || (bean.getCloudShopType() & CLOUD_SHOP_TYPE.CLOUD_SHOP_TYPE_SQUARE) <= 0) && ShopCategoryMan.validShopType(ShopCategoryMan.shopTypeGroup, shopCategory)) {
            if (checkRecommend && checkRecommend && 0 == bean.getIsRecommend2()) {//如果是获取推荐的 该店不为推荐店铺 则略过
                return false;
            }
        } else {
            if (checkRecommend && 0 != 1 - bean.getIsRecommend()) {
                return false;
            }
        }

        return true;
    }

    public static ShopInfo getShopDis(ShopInfo a, Integer sortType, Double lat, Double lng) {
        Long agentByShopId = ShopAgentRelationMemory.getInstance().getAgentByShopId(a.getId());
        a.setAgentId(agentByShopId);

        // 计算定位问题
        if (sortType != null && (sortType == SHOP_LIST_ORDER_TYPE.SPEED
                || sortType == SHOP_LIST_ORDER_TYPE.AGGREGATE
                || sortType == SHOP_LIST_ORDER_TYPE.DISTANCE)) {
            if (ValidateUtil.isLatLng(a.getLat(), a.getLng()) && ValidateUtil.isLatLng(lat, lng)) {
                a.setDistinct(Geohash.distance(a.getLat(), a.getLng(), lat, lng));
            } else {
                a.setDistinct(0.0d);
            }
        }
        return a;
    }

    // 搜索店铺  也能搜索商品
    public static JYPageUtils.PageList getShopListV2(UserInfo user,//用来判断是否收藏过
                                                     boolean checkTypeId,//检测不同类型店铺
                                                     Integer typeId,//不同类型店铺（检测店铺类型时，此参数才有效）
                                                     String city,
                                                     Long regionId,
                                                     Long agentId,//精确商圈代理Id
                                                     Double lng, Double lat,
                                                     String content,//检索内容
                                                     Boolean checkRecommend,//是否检测是否推荐
                                                     Boolean isRecommend,//是否推荐（只有检测推荐时，此参数才有效）
                                                     Boolean checkIsPreference,//是否检测是否优选
                                                     Boolean isPreference, //是否为优选（只有检测推荐时，此参数才有效）
                                                     boolean hasGameInfo,//是否包含活动信息
                                                     Integer orderType,//排序方式   1综合排序  2距离排序 3销量排序 4评分最高 5起送加最低
                                                     String filterType,//筛选条件
                                                     Integer isGroupShop,//是不是团购商家
                                                     Integer needGoods, // 店铺需要返回商品列表
                                                     Integer needGoodsCount, // 店铺需要返回商品列表
                                                     FilterConditionUtils filterConditionUtils,
                                                     Integer page, Integer size) {

        if (null == typeId) {
            checkTypeId = false;
        }
        //是否需要获取店铺当前实时位置
        boolean needShopNowPosition = false;
        if (null != SYS_SETTINGS.SHOP_NOW_POSITION_NEED) {
            needShopNowPosition = (0 == SYS_SETTINGS.SHOP_NOW_POSITION_NEED - 1);
        }
        HashSet<Integer> filterSet = filterToSet(filterType);
        List<ShopInfo> list = null;
        if (ValidateUtil.isID(agentId)) {
            // 首先查出所有的商品来
            list = ShopMan.listOfAgentId(agentId, typeId, null, checkRecommend, isRecommend, checkIsPreference, isPreference);
        } else {
            if (ValidateUtil.isLatLng(lat, lng)) {
                //精确商圈方式
                if (null != SYS_SETTINGS.SHOP_MANAGE_TYPE && 0 == SHOP_MANAGE_TYPE_FREE_OR_AGENT.AGENT - SYS_SETTINGS.SHOP_MANAGE_TYPE) {
                    List<Long> shopIds = new ArrayList<>();
                    //单商圈还是多商圈同时返回
                    if (null != SYS_SETTINGS.LOCAL_CITY_AGENT_TYPE && 0 == SYS_SETTINGS.LOCAL_CITY_AGENT_TYPE) { //定位时城市按下商圈列表还是单独商圈  1单独商圈，0商圈列表
                        //商圈列表
                        List<CityAgentVO> agentList = CityAgentMan.getCityAgentList(city, lat, lng);
                        if (ValidateUtil.isAbsList(agentList)) {
                            list = new ArrayList<>();
                            for (int i = 0; i < agentList.size(); i++) {
                                CityAgentVO agentVO = agentList.get(i);
                                if (null == agentVO) {
                                    continue;
                                }
                                List<Long> tmpList = ShopAgentRelationMemory.getInstance().listOfAgentId(agentVO.getId());
                                if (!ValidateUtil.isAbsList(tmpList)) {
                                    continue;
                                }
                                List<ShopInfo> tList = convertShopList(agentVO, tmpList, lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, null, needShopNowPosition, isGroupShop, null, filterSet);
                                if (ValidateUtil.isAbsList(tList)) {
                                    list.addAll(tList);
                                }
                            }
                        }

                    } else {
                        //单独商圈
                        CityAgentVO cityAgentVO = CityAgentMan.getCityAgent(city, lat, lng);
                        if (null == cityAgentVO) {
                            if (null != SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT && 0 == 1 - SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT) {
                                list = getDefaultShopList(lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, null, needShopNowPosition, isGroupShop, filterSet);
                            } else {
                                return null;
                            }
                        } else {
                            shopIds = ShopAgentRelationMemory.getInstance().listOfAgentId(cityAgentVO.getId());

                            if (ValidateUtil.isAbsList(shopIds)) {
                                list = convertShopList(cityAgentVO, shopIds, lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, null, needShopNowPosition, isGroupShop, null, filterSet);
                            }
                        }
                    }
                } else {
                    Long areaPoint = Geohash.getArea(lat, lng);
                    int range = 15;//大概是10公里
                    if (ValidateUtil.isAbsInteger(SYS_SETTINGS.SHOP_RANGE)) {
                        range = SYS_SETTINGS.SHOP_RANGE;
                    }
                    Set<Long> areaPoints = Geohash.getAroundArea(areaPoint, range);
                    if (ValidateUtil.isID(regionId)) {
                        List<ShopRegionRelation> relationList = ShopRegionRelationMemory.getInstance().listOfRegionId(regionId);
                        if (ValidateUtil.isAbsList(relationList)) {
                            for (int i = 0; i < relationList.size(); i++) {
                                if (null == relationList.get(i)) {
                                    continue;
                                }
                                ShopInfo shopInfo = ShopMemory.getInstance().getShopById(relationList.get(i).getShopId());
                                if (!isUsefulShop(shopInfo, lat, lng, checkRecommend, false, checkTypeId, typeId, null, isGroupShop, null, filterSet)) {
                                    continue;
                                }
                                if (!areaPoints.contains(shopInfo.getAreaPoint())) {
                                    continue;
                                }
                                //获取店铺当前位置
                                if (needShopNowPosition) {
                                    shopInfo = setShopNowPosition(shopInfo);
                                }
                                shopInfo.setDistinct(Geohash.distance(lat, lng, shopInfo.getLat(), shopInfo.getLng()));
                                list.add(shopInfo);
                            }
                        }
                    } else {
                        List<ShopInfo> tmp = ShopMemory.getInstance().list(checkTypeId, typeId,
                                city, "", "",
                                null,
                                checkRecommend, isRecommend, checkIsPreference, isPreference);//该城市店铺列表
                        if (ValidateUtil.isAbsList(tmp)) {
                            list = new ArrayList<>();
                            for (int i = 0; i < tmp.size(); i++) {
                                if (null == tmp.get(i)) {
                                    continue;
                                }
                                if (ValidateUtil.isNotLatLng(lat, lng)) {
                                    continue;
                                }
                                if (ValidateUtil.isNotAbsLong(tmp.get(i).getAreaPoint())) {
                                    continue;
                                }
                                if (!areaPoints.contains(tmp.get(i).getAreaPoint())) {
                                    continue;
                                }
                                //获取店铺当前位置
                                if (needShopNowPosition) {
                                    ShopInfo shopInfo = setShopNowPosition(tmp.get(i));
                                    tmp.get(i).setLat(shopInfo.getLat());
                                    tmp.get(i).setLng(shopInfo.getLng());
                                }
                                tmp.get(i).setDistinct(Geohash.distance(lat, lng, tmp.get(i).getLat(), tmp.get(i).getLng()));
                                list.add(tmp.get(i));
                            }
                        }
                    }
                }

                if (ValidateUtil.isAbsList(list)) {

                } else {
                    if (null != SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT && 0 == 1 - SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT) {
                        list = getDefaultShopList(lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, null, needShopNowPosition, isGroupShop, filterSet);
                    } else {
                        return null;
                    }
                }
            } else {
                list = ShopMemory.getInstance().list(checkTypeId, typeId,
                        city, "", "",
                        null,
                        checkRecommend, isRecommend, checkIsPreference, isPreference);//该城市店铺列表  管理后台可能用到
            }
        }
        if (!ValidateUtil.isAbsList(list)) {
            if (null != SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT && 0 == 1 - SYS_SETTINGS.NO_SHOP_SHOW_DEFAULT) {
                list = getDefaultShopList(lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, null, needShopNowPosition, isGroupShop, filterSet);
            } else {
                return null;
            }
        }

        // 拿到所有的店铺 。。。。  然后进行匹配
        // 删除积分商城的店铺
        List<ShopInfoAndGameVO> reList = new ArrayList<>();
        if (ValidateUtil.isAbsList(list)) {
            // 删除商城的
            for (ShopInfo s : list) {
                // 是不是团购店铺  2019年4月19日18:39:49
                if (isGroupShop != null) {
                    if (s.getIsGroupShop() == null || s.getIsGroupShop() != isGroupShop) {
                        continue;
                    }
                }
                // end
                if (s.getIsIntegralShop() == null || s.getIsIntegralShop() == SHOP_IS_INTEGRAL.NON_INTEGRAL_SHOP || s.getIsIntegralShop() == SHOP_IS_INTEGRAL.BOTH_SHOP) {

                } else {
                    // 积分商城
                    continue;
                }

            }
        }
        if (ValidateUtil.isAbsList(reList)) {
            // 排序
            if (ValidateUtil.isNotAbsInteger(orderType)) {
                orderType = SHOP_LIST_ORDER_TYPE.AGGREGATE;
            }
            // 计算定位问题
            if (orderType == SHOP_LIST_ORDER_TYPE.SPEED
                    || orderType == SHOP_LIST_ORDER_TYPE.AGGREGATE
                    || orderType == SHOP_LIST_ORDER_TYPE.DISTANCE) {
                for (ShopInfoAndGameVO shopInfoAndGameVO : reList) {
                    if (shopInfoAndGameVO != null && ValidateUtil.isLatLng(shopInfoAndGameVO.getLat(), shopInfoAndGameVO.getLng()) && ValidateUtil.isLatLng(lat, lng)) {
                        shopInfoAndGameVO.setDistinct(Geohash.distance(shopInfoAndGameVO.getLat(), shopInfoAndGameVO.getLng(), lat, lng));
                    } else {
                        shopInfoAndGameVO.setDistinct(0.0d);
                    }
                }
            }
            if (null != orderType) {
                switch (orderType) {
                    case SHOP_LIST_ORDER_TYPE.SPEED: //速度最快
                    case SHOP_LIST_ORDER_TYPE.AGGREGATE: {//综合排序
                        Collections.sort(reList, new Comparator<ShopInfoAndGameVO>() {
                            // 1  先按序号升序，序号相同 则距离升序
                            public int compare(ShopInfoAndGameVO arg0, ShopInfoAndGameVO arg1) {
                                if (arg0.getOrderNo().compareTo(arg1.getOrderNo()) == 0) {
                                    return arg0.getDistinct().compareTo(arg1.getDistinct()) > 0 ? 1 : -1;
                                } else {
                                    return (int) (arg0.getOrderNo() - arg1.getOrderNo());
                                }
                            }
                        });
                    }
                    break;
                    case SHOP_LIST_ORDER_TYPE.DISTANCE: {//距离排序
                        reList.sort(Comparator.nullsLast(Comparator.comparingDouble(ShopInfoAndGameVO::getDistinct)));
                    }
                    break;
                    case SHOP_LIST_ORDER_TYPE.SELL_COUNT: {//销量排序
                        // 销量类型0：月销量1：总销量
                        if (null != SYS_SETTINGS.SELL_COUNT_TYPE && 0 == SYS_SETTINGS.SELL_COUNT_TYPE) {
                            Collections.sort(reList, new Comparator<ShopInfoAndGameVO>() {
                                public int compare(ShopInfoAndGameVO arg0, ShopInfoAndGameVO arg1) {
                                    return arg1.getMonthOrderCount().compareTo(arg0.getMonthOrderCount());//销量排序
                                }
                            });
                        } else {
                            Collections.sort(reList, new Comparator<ShopInfoAndGameVO>() {
                                public int compare(ShopInfoAndGameVO arg0, ShopInfoAndGameVO arg1) {
                                    return arg1.getOrderCounts().compareTo(arg0.getOrderCounts());//销量排序
                                }
                            });
                        }
                    }
                    break;
                    case SHOP_LIST_ORDER_TYPE.SCORE: {//评分最高
                        Collections.sort(reList, new Comparator<ShopInfoAndGameVO>() {
                            public int compare(ShopInfoAndGameVO arg0, ShopInfoAndGameVO arg1) {
                                return arg1.getScore().compareTo(arg0.getScore());//按距离排序
                            }
                        });
                    }
                    break;
                    case SHOP_LIST_ORDER_TYPE.DELIVERY_PRICE: {//起送加最低
                        Collections.sort(reList, new Comparator<ShopInfoAndGameVO>() {
                            public int compare(ShopInfoAndGameVO arg0, ShopInfoAndGameVO arg1) {
                                return arg1.getStartFree().compareTo(arg0.getStartFree());//起送加最低
                            }
                        });
                    }
                    break;
                }
            }
            Collections.sort(reList, new Comparator<ShopInfoAndGameVO>() {
                @Override
                public int compare(ShopInfoAndGameVO o1, ShopInfoAndGameVO o2) {
                    if (o1.getIsWork() < o2.getIsWork()) {
                        return 1;
                    }
                    if (o1.getIsWork() == o2.getIsWork()) {
                        return 0;
                    }
                    return -1;
                }
            });
            if (null == page || page < 1) {
                page = 1;
            }
            if (null == size || size < 1) {
                size = 10;
            }

            JYPageUtils.PageList pageList = JYPageUtils.getList(reList, page, size);

            return pageList;
        }
        return null;
    }


    //获取店铺的简单信息
    public static ShopInfoAndGameVO getShop(UserInfo user, ShopInfo info, boolean hasGameInfo, Integer needGoods, Integer needGoodsCount, Integer shopCategory) {
        ShopInfoAndGameVO shopInfoVO = new ShopInfoAndGameVO();
        try {
            ObjectUtils.copyPropertiesExclude(info, shopInfoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        if (null == shopInfoVO) {
            return null;
        }
        //登录用户判断是否收藏过
        if (user != null && ShopLikeMemory.getInstance().isLike(user.getUsername(), shopInfoVO.getId())) {//登录用户判断是否收藏
            shopInfoVO.setIsLike(1);
            // 是不是 购买过过
            boolean b = OrderInfoMemory.getInstance().hasOrderInShopId(user.getUsername(), shopInfoVO.getId());
            if (b) {
                shopInfoVO.setIsOftenBrowse(1);
            }
        }
        //获取店铺评分、星级、销量
        ShopInfoExtra extraInfo = ShopExtraInfoMemory.getInstance().getShopExtraInfoById(shopInfoVO.getId());
        if (null != extraInfo) {
            shopInfoVO.setStar(extraInfo.getStar());
            shopInfoVO.setScore(JYMathDoubleUtils.round(extraInfo.getScore(), 1));
            shopInfoVO.setOrderCounts(extraInfo.getOrderCounts());
            shopInfoVO.setMonthOrderCount(extraInfo.getMonthOrderCount());
            shopInfoVO.setShowOrderCounts(extraInfo.getShowOrderCounts());
            shopInfoVO.setShopTag(extraInfo.getShopTag());
            shopInfoVO.setGoodsCount(extraInfo.getGoodsCount());
        }


        return shopInfoVO;
    }


    // 是不是包含指定的keys
    public static boolean hasKeyword(String target, String keyword) {
        if (ValidateUtil.isNotNull(target) && target.contains(keyword)) {
            return true;
        }
        // 例如搜索的y 既能搜索到 呀 也能 搜索到 一
        if (ValidateUtil.isNotNull(target) && ValidateUtil.isNotNull(keyword)) {
            target = JYPinyinHelper.toHanyuPinyin(target);
            if (ValidateUtil.isNotNull(target) && target.toUpperCase().contains(keyword.toUpperCase())) {
                return true;
            }
        }
        return false;
    }
    //----------------------------------------------
    //检测店铺
    public static boolean isUsefulShop(ShopInfo shopInfo,
                                       Double lat, Double lng,
                                       boolean checkRecommend,
                                       boolean checkIsPreference,
                                       boolean checkTypeId, Integer typeId,
                                       String content,
                                       Integer shopCategroy,
                                       Set<Long> shopIdSet,
                                       HashSet<Integer> filterSet//筛选条件
    ) {
        if (null == shopInfo) {
            return false;
        }

        if (shopInfo.getIsIntegralShop() == null
                || shopInfo.getIsIntegralShop() == SHOP_IS_INTEGRAL.NON_INTEGRAL_SHOP || shopInfo.getIsIntegralShop() == SHOP_IS_INTEGRAL.BOTH_SHOP) {
        } else {
            // 积分商城
            return false;
        }

        if (ValidateUtil.isNotLatLng(lat, lng)) {
            return false;
        }
        if (shopCategroy == null) {
            shopCategroy = ShopCategoryMan.shopTypeShopping; // 默认为外卖的
        }
        if (shopInfo.getShopCategory() != null) {
            if (!ShopCategoryMan.validShopType(shopCategroy, shopInfo.getShopCategory())) {
                return false;
            }
        }
        if (SYS_SETTINGS.DISTINGUISH_SHOP_RECOMMEND == 1 && (shopInfo.getCloudShopType() == null || (shopInfo.getCloudShopType() & CLOUD_SHOP_TYPE.CLOUD_SHOP_TYPE_SQUARE) <= 0) && shopCategroy != null && ShopCategoryMan.validShopType(ShopCategoryMan.shopTypeGroup, shopCategroy)) {
            if (checkRecommend && checkRecommend && 0 == shopInfo.getIsRecommend2()) {//如果是获取推荐的 该店不为推荐店铺 则略过
                return false;
            }
        } else {
            if (checkRecommend && 0 != 1 - shopInfo.getIsRecommend()) {
                return false;
            }
        }

//        //是否推荐
//        if (checkRecommend && 0 != 1 - shopInfo.getIsRecommend()) {
//            return false;
//        }

        if (SYS_SETTINGS.DISTINGUISH_SHOP_RECOMMEND == 1 && (shopInfo.getCloudShopType() == null || (shopInfo.getCloudShopType() & CLOUD_SHOP_TYPE.CLOUD_SHOP_TYPE_SQUARE) <= 0) && shopCategroy != null && ShopCategoryMan.validShopType(ShopCategoryMan.shopTypeGroup, shopCategroy)) {
            if (checkIsPreference && 0 != 1 - shopInfo.getIsPreference2()) {
                return false;
            }
        } else {
            if (checkIsPreference && 0 != 1 - shopInfo.getIsPreference()) {
                return false;
            }
        }
        // 检测 优选 2019年5月31日11:24:58
//        if (checkIsPreference && 0 != 1 - shopInfo.getIsPreference()) {
//            return false;
//        }
        // end
        //是否满足筛选条件
//        if (null != filterSet && filterSet.size() > 0) {
//            //------配送方式
//            ShopInfoExtra infoExtra = ShopExtraInfoMemory.getInstance().getShopExtraInfoById(shopInfo.getId());
//            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PLATFORM)) {//需平台配送
//                if (0 == shopInfo.getIsPeiSong() || (null != shopInfo.getIsSelfPost() && 0 != shopInfo.getIsSelfPost())) {
//                    return false;
//                }
//            }
//            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_SHOP_SELF_POST)) {//需自配送
//                if (0 == shopInfo.getIsPeiSong() || (null != shopInfo.getIsSelfPost() && 0 != 1 - shopInfo.getIsSelfPost())) {
//                    return false;
//                }
//            }
//            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_SELF_PULL)) {//需到店自取
//                if (0 == shopInfo.getIsDaoDian()) {//不支持到店
//                    return false;
//                }
//            }
//            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_SELF_TO_SHOP)) {//到店堂食
//                if (0 != 2 - shopInfo.getIsDaoDian()) {//不支持到店堂食
//                    return false;
//                }
//            }
//            //------运费
//            //配送费计算方式
//            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_NONE)
//                    || filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_SUB)) {//免配送费 减配送费
//                /**
//                 *  情况1. 标签
//                 *  情况2. 标记为免
//                 *  情况3. 费用计算全为0
//                 *  情况4. 最小费用小于减去的费用
//                 */
//                boolean mianPeiFlag = true;
//                // 情况1. 标签
//                if (infoExtra != null && infoExtra.getShopTag() != null && (infoExtra.getShopTag() - SHOP_TAG.MIAN_PEI == 0)) {
//                    // 情况1. 标签
//                } else if (ValidateUtil.isAbsDouble(shopInfo.getFreeYunFei()) && shopInfo.getFreeYunFeiMoney() != null && shopInfo.getFreeYunFeiMoney() == -1) {
//                    //  情况2. 标记为免
//                } else {
//                    // 情况3. 费用计算全为0
//                    // 情况4. 最小费用小于减去的费用
//                    Double fixedCost = shopInfo.getFixedCost();
//                    Double withinDistance = shopInfo.getWithinDistance();
//                    Double oneKmCost = shopInfo.getOneKmCost();
//                    if (ValidateUtil.isNotAbsDouble(fixedCost) && ValidateUtil.isNotAbsDouble(withinDistance) && ValidateUtil.isNotAbsDouble(oneKmCost)) {
//                        Long agentId = ShopAgentRelationMemory.getInstance().getAgentByShopId(shopInfo.getId());
//                        CityAgent cityAgent = CityAgentMemory.getInstance().getById(agentId);
//                        if (cityAgent != null) {
//                            fixedCost = cityAgent.getFixedCost();
//                            withinDistance = cityAgent.getWithinDistance();
//                            oneKmCost = cityAgent.getOneKmCost();
//                        }
//                    }
//                    if (ValidateUtil.isNotAbsDouble(shopInfo.getYunfei()) && ValidateUtil.isNotAbsDouble(fixedCost) && ValidateUtil.isNotAbsDouble(withinDistance) && ValidateUtil.isNotAbsDouble(oneKmCost)) {
//                        // 情况3. 费用计算全为0
//                    } else if (ValidateUtil.isAbsDouble(shopInfo.getFreeYunFei()) && ValidateUtil.isNotAbsDouble(shopInfo.getYunfei()) && shopInfo.getFreeYunFeiMoney() != null && fixedCost <= shopInfo.getFreeYunFeiMoney()) {
//                        // 情况4. 最小费用小于减去的费用
//                    } else {
//                        mianPeiFlag = false;
//                    }
//                }
//                if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_NONE) && !mianPeiFlag) {
//                    return false;
//                }
//                if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_SUB)) {
//                    if (mianPeiFlag || (ValidateUtil.isAbsDouble(shopInfo.getFreeYunFei()) && ValidateUtil.isAbsDouble(shopInfo.getFreeYunFeiMoney()))) {
//                    } else {
//                        return false;
//                    }
//                }
//            }
//
//            // if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_NONE)
//            //         || filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_SUB)) {//免配送费 减配送费
//            //
//            //     if ((null != shopInfo.getYunfei() && ValidateUtil.isNotAbsDouble(shopInfo.getYunfei()))
//            //             || (null != shopInfo.getFreeYunFeiMoney() && -1 == shopInfo.getFreeYunFeiMoney())) {
//            //         if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_NONE) && ValidateUtil.isAbsDouble(shopInfo.getFixedCost())) {//免配送费
//            //             return false;
//            //         }
//            //         //免配送费
//            //     } else if (null != shopInfo.getFreeYunFeiMoney() && shopInfo.getFreeYunFeiMoney() > 0) {
//            //         //减配送费
//            //         if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_NONE)) {//免配送费
//            //             return false;
//            //         }
//            //     } else {
//            //         if (infoExtra != null && infoExtra.getShopTag() != null && (infoExtra.getShopTag() == SHOP_TAG.MIAN_PEI)) {
//            //
//            //         } else {
//            //             return false;
//            //         }
//            //     }
//            // }
//
//            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_START_ZERO)) {//新商家
//                if (null == shopInfo.getStartFree() || 0 == shopInfo.getStartFree()) {
//                    //0元起送
//                } else {
//                    if (infoExtra != null && infoExtra.getShopTag() != null && (infoExtra.getShopTag() == SHOP_TAG.MIAN_PEI)) {
//
//                    } else {
//                        return false;
//                    }
//                    // return false;
//                }
//            }
//
//            if (filterSet.contains(SHOP_FILTER_TYPE.SHOP_NEW)) {//新商家
//                if ((shopInfo.getCreateTime() > DateUtils.getCurrTime() - 30 * 24 * 60 * 60 * 1000) || shopInfo.getIsNewOpen() == 1) {
//                    // 新商家
//                } else {
//                    if (infoExtra != null && infoExtra.getShopTag() != null && infoExtra.getShopTag() == SHOP_TAG.XIN_DIAN) {
//
//                    } else {
//                        return false;
//                    }
//                }
//            }
//
//            // 常逛商家
//            if (filterSet.contains(SHOP_FILTER_TYPE.FREQUENT_STROLL)) {// 常逛
//                if (shopIdSet != null && shopIdSet.contains(shopInfo.getId())) {
//                    // 常逛
//                } else {
//                    return false;
//                }
//            }
//            // 品牌内页
//            if (filterSet.contains(SHOP_FILTER_TYPE.SHOP_BRAND)) {// 常逛
//                if (shopInfo.getShopRole() != null && shopInfo.getShopRole() == SHOP_ROLE.BRAND) {
//                    // 原先版本 品牌商家
//                } else {
//                    if (infoExtra != null && infoExtra.getShopTag() != null && infoExtra.getShopTag() == SHOP_TAG.SHOP_BRAND) {
//                        // 修改后品牌商家
//                    } else {
//                        return false;
//                    }
//                }
//            }
//            if (filterSet.contains(SHOP_FILTER_TYPE.SHOP_SCORE)) {//点评高分
//                if (null != shopInfo.getStar() && shopInfo.getStar() >= 4) {
//                    // 点评高
//                } else {
//                    return false;
//                }
//            }
//            // 优惠
//            if (filterSet.contains(SHOP_FILTER_TYPE.AWARD_SHOP) || filterSet.contains(SHOP_FILTER_TYPE.AWARD_MONEY_FULL)
//                    || filterSet.contains(SHOP_FILTER_TYPE.AWARD_MONEY_FIRST)
//                    || filterSet.contains(SHOP_FILTER_TYPE.AWARD_GIFT)
//                    || filterSet.contains(SHOP_FILTER_TYPE.AWARD_GIFT_FIRST)) {
//                // 是否需要判断优惠
//                List<GameInfoAndRulesVO> gameList = Game.listOfShopId(shopInfo.getId(), false);
//                if (ValidateUtil.isAbsList(gameList)) {
//                    //有活动
//                } else {
//                    //无活动
//                    if (infoExtra != null && infoExtra.getShopTag() != null && (infoExtra.getShopTag() == SHOP_TAG.YOU_HUI || infoExtra.getShopTag() == SHOP_TAG.WU_ZHE)) {
//
//                    } else {
//                        return false;
//                    }
//                    // return false;
//                }
//            }
//        }
        // 筛选过滤条件
        if (!screenShopFilter(filterSet, shopIdSet, shopInfo)) {
            return false;
        }

        //是否所属类型
        if (checkTypeId && !ShopTypeRelationMemory.getInstance().shopInType(shopInfo.getId(), typeId)) {
            return false;
        }

        //判断检索
        if (ValidateUtil.isNotNull(content) &&
                !(SysCommon.hasKeyword(shopInfo.getShopName(), content)
                        || SysCommon.hasKeyword(shopInfo.getAffiche(), content)
                        || SysCommon.hasKeyword(shopInfo.getRegion(), content)
                        || SysCommon.hasKeyword(shopInfo.getDescs(), content))) {//如果需要判断搜索，搜索内容不包含
            return false;
        }
        return true;
    }

    /**
     * 过滤商家是否
     *
     * @param filterSet
     * @param shopIdSet
     * @param shopInfo
     * @return
     */
    public static boolean screenShopFilter(HashSet<Integer> filterSet, Set<Long> shopIdSet, ShopInfo shopInfo) {
        if (null != filterSet && filterSet.size() > 0) {
            //------配送方式
            ShopInfoExtra infoExtra = ShopExtraInfoMemory.getInstance().getShopExtraInfoById(shopInfo.getId());
            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PLATFORM)) {//需平台配送
                if (0 == shopInfo.getIsPeiSong() || (null != shopInfo.getIsSelfPost() && 0 != shopInfo.getIsSelfPost())) {
                    return false;
                }
            }
            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_SHOP_SELF_POST)) {//需自配送
                if (0 == shopInfo.getIsPeiSong() || (null != shopInfo.getIsSelfPost() && 0 != 1 - shopInfo.getIsSelfPost())) {
                    return false;
                }
            }
            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_SELF_PULL)) {//需到店自取
                if (0 == shopInfo.getIsDaoDian()) {//不支持到店
                    return false;
                }
            }
            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_SELF_TO_SHOP)) {//到店堂食
                if (0 != 2 - shopInfo.getIsDaoDian()) {//不支持到店堂食
                    return false;
                }
            }
            //------运费
            //配送费计算方式
            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_NONE)
                    || filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_SUB)) {//免配送费 减配送费
                /**
                 *  情况1. 标签
                 *  情况2. 标记为免
                 *  情况3. 费用计算全为0
                 *  情况4. 最小费用小于减去的费用
                 */
                boolean mianPeiFlag = true;
                // 情况1. 标签
                if (infoExtra != null && infoExtra.getShopTag() != null && (infoExtra.getShopTag() - SHOP_TAG.MIAN_PEI == 0)) {
                    // 情况1. 标签
                } else if (ValidateUtil.isAbsDouble(shopInfo.getFreeYunFei()) && shopInfo.getFreeYunFeiMoney() != null && shopInfo.getFreeYunFeiMoney() == -1) {
                    //  情况2. 标记为免
                } else {
                    // 情况3. 费用计算全为0
                    // 情况4. 最小费用小于减去的费用
                    Double fixedCost = shopInfo.getFixedCost();
                    Double withinDistance = shopInfo.getWithinDistance();
                    Double oneKmCost = shopInfo.getOneKmCost();
                    if (ValidateUtil.isNotAbsDouble(fixedCost) && ValidateUtil.isNotAbsDouble(withinDistance) && ValidateUtil.isNotAbsDouble(oneKmCost)) {
                        Long agentId = ShopAgentRelationMemory.getInstance().getAgentByShopId(shopInfo.getId());
                        CityAgent cityAgent = CityAgentMemory.getInstance().getById(agentId);
                        if (cityAgent != null) {
                            fixedCost = cityAgent.getFixedCost();
                            withinDistance = cityAgent.getWithinDistance();
                            oneKmCost = cityAgent.getOneKmCost();
                        }
                    }
                    if (ValidateUtil.isNotAbsDouble(shopInfo.getYunfei()) && ValidateUtil.isNotAbsDouble(fixedCost) && ValidateUtil.isNotAbsDouble(withinDistance) && ValidateUtil.isNotAbsDouble(oneKmCost)) {
                        // 情况3. 费用计算全为0
                    } else if (ValidateUtil.isAbsDouble(shopInfo.getFreeYunFei()) && ValidateUtil.isNotAbsDouble(shopInfo.getYunfei()) && shopInfo.getFreeYunFeiMoney() != null && fixedCost <= shopInfo.getFreeYunFeiMoney()) {
                        // 情况4. 最小费用小于减去的费用
                    } else {
                        mianPeiFlag = false;
                    }
                }
                if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_NONE) && !mianPeiFlag) {
                    return false;
                }
                if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_SUB)) {
                    if (mianPeiFlag || (ValidateUtil.isAbsDouble(shopInfo.getFreeYunFei()) && ValidateUtil.isAbsDouble(shopInfo.getFreeYunFeiMoney()))) {
                    } else {
                        return false;
                    }
                }
            }
            if (filterSet.contains(SHOP_FILTER_TYPE.DELIVERY_PRICE_START_ZERO)) {//新商家
                if (null == shopInfo.getStartFree() || 0 == shopInfo.getStartFree()) {
                    //0元起送
                } else {
                    if (infoExtra != null && infoExtra.getShopTag() != null && (infoExtra.getShopTag() == SHOP_TAG.MIAN_PEI)) {

                    } else {
                        return false;
                    }
                }
            }

            if (filterSet.contains(SHOP_FILTER_TYPE.SHOP_NEW)) {//新商家
                if ((shopInfo.getCreateTime() > DateUtils.getCurrTime() - 30 * 24 * 60 * 60 * 1000) || shopInfo.getIsNewOpen() == 1) {
                    // 新商家
                } else {
                    if (infoExtra != null && infoExtra.getShopTag() != null && infoExtra.getShopTag() == SHOP_TAG.XIN_DIAN) {

                    } else {
                        return false;
                    }
                }
            }

            // 常逛商家
            if (filterSet.contains(SHOP_FILTER_TYPE.FREQUENT_STROLL)) {// 常逛
                if (shopIdSet != null && shopIdSet.contains(shopInfo.getId())) {
                    // 常逛
                } else {
                    return false;
                }
            }
            // 品牌内页
            if (filterSet.contains(SHOP_FILTER_TYPE.SHOP_BRAND)) {// 常逛
                if (shopInfo.getShopRole() != null && shopInfo.getShopRole() == SHOP_ROLE.BRAND) {
                    // 原先版本 品牌商家
                } else {
                    if (infoExtra != null && infoExtra.getShopTag() != null && infoExtra.getShopTag() == SHOP_TAG.SHOP_BRAND) {
                        // 修改后品牌商家
                    } else {
                        return false;
                    }
                }
            }
            if (filterSet.contains(SHOP_FILTER_TYPE.SHOP_SCORE)) {//点评高分
                if (null != shopInfo.getStar() && shopInfo.getStar() >= 4) {
                    // 点评高
                } else {
                    return false;
                }
            }

        }
        return true;
    }

    //获取店铺当前位置
    private static ShopInfo setShopNowPosition(ShopInfo shopInfo) {
        if (null == shopInfo) {
            return null;
        }

        ShopPositionInfo shopPositionInfo = ShopPositionMemory.getInstance().get(shopInfo.getId());
        if (null != shopPositionInfo) {
            shopInfo.setLat(shopPositionInfo.getLat());
            shopInfo.setLng(shopPositionInfo.getLng());
            shopInfo.setAddress(shopPositionInfo.getAddress());
            shopInfo.setCity(shopPositionInfo.getCity());
            shopInfo.setProvince(shopPositionInfo.getProvince());
        }

        return shopInfo;
    }


    //店铺列表信息
    public static List<ShopInfo> convertShopList(CityAgentVO cityAgentVO,
                                                 List<Long> shopIds,
                                                 Double lat, Double lng,
                                                 Boolean checkRecommend,
                                                 Boolean checkIsPreference,// 检测优选
                                                 Boolean checkTypeId,
                                                 Integer typeId,
                                                 String content,
                                                 Boolean needShopNowPosition,
                                                 Integer shopCategory,
                                                 Set<Long> userBuyShopIdSet,
                                                 HashSet<Integer> filterType) {
        if (null == cityAgentVO) {
            return null;
        }
        boolean userAgentYunfei = false;//使用商圈的运费规则
        if (null != SYS_SETTINGS.SELECT_DISTRIBUTION_FEE && 0 == 3 - SYS_SETTINGS.SELECT_DISTRIBUTION_FEE) {
            userAgentYunfei = true;
        }
        if (ValidateUtil.isAbsList(shopIds)) {
            List<ShopInfo> list = new ArrayList<>();
            for (int i = 0; i < shopIds.size(); i++) {
                if (null == shopIds.get(i)) {
                    continue;
                }
                ShopInfo tmpShop = ShopMemory.getInstance().getShopById(shopIds.get(i));
                if (null == tmpShop) {
                    continue;
                }
                ShopInfo shopInfo = new ShopInfo();
                try {
                    ObjectUtils.copyPropertiesExclude(tmpShop, shopInfo);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == shopInfo) {
                    continue;
                }
                if (!isUsefulShop(shopInfo, lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, shopCategory, userBuyShopIdSet, filterType)) {
                    continue;
                }

                //获取店铺当前位置
                if (needShopNowPosition) {
                    shopInfo = setShopNowPosition(shopInfo);
                }
                // 获取店铺额外信息
                ShopInfoExtra extraInfo = ShopExtraInfoMemory.getInstance().getShopExtraInfoById(shopIds.get(i));
                if (null != extraInfo) {
                    shopInfo.setOrderCounts(extraInfo.getOrderCounts());
                } else {
                    shopInfo.setOrderCounts(0);
                }
                shopInfo.setDistinct(Geohash.distance(lat, lng, shopInfo.getLat(), shopInfo.getLng()));

                if (userAgentYunfei && ValidateUtil.isNotAbsDouble(shopInfo.getFixedCost()) && ValidateUtil.isNotAbsDouble(shopInfo.getWithinDistance()) && ValidateUtil.isNotAbsDouble(shopInfo.getOneKmCost())) {
                    shopInfo.setFixedCost(cityAgentVO.getFixedCost());
                    shopInfo.setWithinDistance(cityAgentVO.getWithinDistance());
                    shopInfo.setOneKmCost(cityAgentVO.getOneKmCost());
                }

                list.add(shopInfo);
            }
            return list;
        }
        return null;
    }

    //获取默认店铺列表
    private static List<ShopInfo> getDefaultShopList(Double lat, Double lng,
                                                     Boolean checkRecommend,
                                                     Boolean checkIsPreference,
                                                     Boolean checkTypeId, Integer typeId,
                                                     String content,
                                                     Boolean needShopNowPosition,
                                                     Integer shopCategory,
                                                     HashSet<Integer> filterType) {
        return getDefaultShopList(lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, needShopNowPosition, shopCategory, null, filterType);
    }

    //获取默认店铺列表
    private static List<ShopInfo> getDefaultShopList(Double lat, Double lng,
                                                     Boolean checkRecommend,
                                                     Boolean checkIsPreference,
                                                     Boolean checkTypeId, Integer typeId,
                                                     String content,
                                                     Boolean needShopNowPosition,
                                                     Integer shopCategory,
                                                     Set<Long> userBuySet,
                                                     HashSet<Integer> filterType) {
        List<ShopInfo> list = ShopMemory.getInstance().list();
        if (ValidateUtil.isAbsList(list)) {

            List<ShopInfo> reList = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                ShopInfo shopInfo = list.get(i);
                if (null == shopInfo) {
                    continue;
                }
                if (!isUsefulShop(shopInfo, lat, lng, checkRecommend, checkIsPreference, checkTypeId, typeId, content, shopCategory, userBuySet, filterType)) {
                    continue;
                }

                //获取店铺当前位置
                if (needShopNowPosition) {
                    shopInfo = setShopNowPosition(shopInfo);
                }
                // 获取店铺额外信息
                ShopInfoExtra extraInfo = ShopExtraInfoMemory.getInstance().getShopExtraInfoById(shopInfo.getId());
                if (null == extraInfo) {
                    continue;
                }
                shopInfo.setOrderCounts(extraInfo.getOrderCounts());
                shopInfo.setDistinct(Geohash.distance(lat, lng, shopInfo.getLat(), shopInfo.getLng()));

                reList.add(shopInfo);
            }

            return reList;
        }
        return null;
    }


    //-------------
    //将筛选条件转为set
    private static HashSet<Integer> filterToSet(String filterType) {
        if (ValidateUtil.isNull(filterType)) {
            return null;
        }
        String arr[] = filterType.split(",");
        if (null != arr && arr.length > 0) {
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < arr.length; i++) {
                String filter = arr[i];
                if (ValidateUtil.isNull(filter)) {
                    continue;
                }
                set.add(Integer.parseInt(filter));
            }
            return set;
        }

        return null;
    }


    // 获取附近的商家 弹出优惠券信息
    public static HashSet<Long> listOfShopId(String city, Long agentId, Double lat, Double lng) {
        HashSet<Long> set = new HashSet<>();
        if (StringUtils.isEmpty(city)) {
            return null;
        }
        if ((agentId == null || agentId <= 0) && !ValidateUtil.isLatLng(lat, lng)) {
            return null;
        }
        if (agentId != null && agentId > 0) {
            List<Long> list = ShopAgentRelationMemory.getInstance().listOfAgentId(agentId);
            if (list != null && list.size() > 0) {
                set.addAll(list);
            }
        } else if (ValidateUtil.isLatLng(lat, lng)) {
            if (null != SYS_SETTINGS.SHOP_MANAGE_TYPE && 0 == SHOP_MANAGE_TYPE_FREE_OR_AGENT.AGENT - SYS_SETTINGS.SHOP_MANAGE_TYPE) {
                //单商圈还是多商圈同时返回
                if (null != SYS_SETTINGS.LOCAL_CITY_AGENT_TYPE && 0 == SYS_SETTINGS.LOCAL_CITY_AGENT_TYPE) {//定位时城市按下商圈列表还是单独商圈  1单独商圈，0商圈列表
                    //商圈列表
                    List<CityAgentVO> agentLists = CityAgentMan.getCityAgentList(city, lat, lng);
                    if (ValidateUtil.isAbsList(agentLists)) {
                        for (int i = 0; i < agentLists.size(); i++) {
                            if (null == agentLists.get(i)) {
                                continue;
                            }
                            List<Long> tmpList = ShopAgentRelationMemory.getInstance().listOfAgentId(agentLists.get(i).getId());
                            if (!ValidateUtil.isAbsList(tmpList)) {
                                continue;
                            }
                            set.addAll(tmpList);
                        }
                    }
                } else {
                    //单独商圈
                    CityAgentVO cityAgentVO = CityAgentMan.getCityAgent(city, lat, lng);
                    if (null == cityAgentVO) {
                        return null;
                    } else {
                        List<Long> shopIds = ShopAgentRelationMemory.getInstance().listOfAgentId(cityAgentVO.getId());
                        if (ValidateUtil.isAbsList(shopIds)) {
                            set.addAll(shopIds);
                        }
                    }
                }
            } else {
                List<ShopInfo> tmp = ShopMemory.getInstance().getCityShopList(city, null, null, null);
                if (tmp == null || tmp.size() == 0) {

                } else {
                    for (ShopInfo shopInfo : tmp) {
                        if (shopInfo == null) {
                            continue;
                        }
                        set.add(shopInfo.getId());
                    }
                }
            }
        }
        return set;
    }

    // 获取指定商家列表的申请时间
    public static void assignmentShopApplyVerifyTime(List<ShopInfoVO> shopInfoVOList) {
        if (!ValidateUtil.isAbsList(shopInfoVOList)) {
            return;
        }
        Set<String> ownUsernameSet = shopInfoVOList.stream().map(item -> "'" + item.getOwnUsername() + "'").collect(Collectors.toSet());
        StringBuilder sql = new StringBuilder();
        sql.append(" select ownUsername,createTime from ").append(PojoTables.ShopVerify)
                .append(" where delFlag = 0 and  verifyStatus = ").append(ShopVerify.OVER)
                .append(" and  ownUsername in (").append(StringUtils.join(ownUsernameSet, ",")).append(")")
                .append(" group by ownUsername ");
        List<ShopVerify> list = null;
        try {
            list = (List<ShopVerify>) UserDaoSql.getInstance().list(ShopVerify.class, sql.toString());
        } catch (Exception e) {
            e.getMessage();
            return;
        }
        if (!ValidateUtil.isAbsList(list)) {
            return;
        }
        Map<String, Long> map = list.stream().collect(Collectors.toMap(ShopVerify::getOwnUsername, ShopVerify::getCreateTime));
        if (!map.isEmpty()) {
            shopInfoVOList.forEach(item -> {
                if (map.containsKey(item.getOwnUsername())) {
                    item.setApplyShopTime(map.get(item.getOwnUsername()));
                }
            });
        }
    }


}
